D. Suit and Tie(水题 模拟) 您所在的位置:网站首页 suits and ties D. Suit and Tie(水题 模拟)

D. Suit and Tie(水题 模拟)

2023-10-09 07:29| 来源: 网络整理| 查看: 265

Note

In the first sample case, we can transform 11233244→11232344→1122334411233244→11232344→11223344 in two steps. Note that the sequence 11233244→11323244→1133224411233244→11323244→11332244 also works in the same number of steps.

The second sample case already satisfies the constraints; therefore we need 00

 swaps

题意:给出一个n,有2×n的数列,每个数字必定出现两次,你可以进行互换操作,即将相邻的两个数互换。问,将所有相同的数字移动到一起,最少需要互换几次。

思路:前面的数字是不动的!如 3 1 2 3 1 2,我们肯定是选择将后面的一那个3往前移动!(如果将前面的3移动到后面的话,在移动1和2时,都将多跨过一个数字,这就使得移动次数不是最少了)照这个思路,for循环,一个一个的开始移动就好了,毕竟n只有100,2*n也才200.

#include using namespace std; int a[210]; int main() { int n,j,ans=0; cin>>n; for(int i=1;i>a[i]; for(int i=2;i


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有